/**
 * 
 */
package com.yst.metho.web.application.reports;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.naming.NamingException;

import com.yst.metho.web.application.utils.AbstractSuiviComparator;
import com.yst.metho.web.application.utils.AbstractSuiviTableModel;
import com.yst.metho.web.application.utils.Locator;
import com.yst.suivi.data.reports.Report;

/**
 * @author perso
 * 
 */
public class ReportListModel extends AbstractSuiviTableModel
{
	private class ReportComparator extends AbstractSuiviComparator
	{

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
		 */
		public int compare(Object o1, Object o2)
		{
			Report u1 = (Report) o1;
			Report u2 = (Report) o2;
			int comparaison = 0;
			comparaison = u1.getNom().compareToIgnoreCase(u2.getNom());
			if (!isAscending())
			{
				comparaison = -1 * comparaison;
			}
			return comparaison;
		}

	}

	private String[] mColumnsName =
	{ "Nom", "Fichier" };
	
	private int reportType;

	// private Collection mProjectsList;

	public ReportListModel(int type) throws NamingException, FinderException, CreateException
	{
		super();
		setComparator(new ReportComparator());
		reportType = type;
		refresh();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.yst.metho.web.application.interfaces.IListingViewModel#refresh()
	 */
	public void refresh()
	{
		try
		{
			mList = Locator.getReportView().findReport(reportType);
			fireTableDataChanged();
		}
		catch (NamingException e)
		{
			throw new RuntimeException(e);
		}
		catch (FinderException e)
		{
			throw new RuntimeException(e);
		}
		catch (CreateException e)
		{
			throw new RuntimeException(e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.table.AbstractTableModel#getColumnName(int)
	 */
	public String getColumnName(int arg0)
	{
		return mColumnsName[arg0];
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.table.TableModel#getColumnCount()
	 */
	public int getColumnCount()
	{
		return mColumnsName.length;
	}
}
